//
//  StepUI.swift
//  uiKit-demo
//
//  Created by 陈澎 on 2024/12/25.
//

import UIKit
class MyStepUI: UIViewController {
    let text = UITextView()
    @objc func onAdd(step: UIStepper) {
        print("\(step.value)")
        text.text = String(step.value)
        if step.value > 5 {
            text.textColor = UIColor.red
        } else {
            text.textColor = UIColor.green
        }
    }
    func render(_ self: AnyObject, target: Any) {
        let stepper = UIStepper()
        text.frame = CGRect(x: stepper.frame.width + 30, y: 1120, width: 100, height: stepper.frame.height)
        text.text = "0.0"
        // 设置字体大小
        text.font = UIFont.systemFont(ofSize: 18)
        text.textColor = UIColor.green
        self.addSubview(text)
        stepper.frame = CGRect(x: 20, y: 1120, width: 0, height: 0)
        stepper.tintColor = UIColor.red
//        stepper.backgroundColor = UIColor.green
        stepper.minimumValue = 0
        stepper.maximumValue = 10
        stepper.stepValue = 1
        // 是否支持连续操作
        stepper.isContinuous = false
        stepper.addTarget(target, action: #selector(onAdd), for: UIControl.Event.valueChanged)
        self.addSubview(stepper)
    }
}
